import datetime

import pygame
from pygame.locals import *

from lib.sittings import info


def go(snake):
    quit = False
    lose = False

    for event in pygame.event.get():
        if event.type == QUIT:
            quit = True
        elif event.type == KEYDOWN:
            currentmovedir = snake.movedir
            if event.key == K_UP:
                tomove = 'up'
                dontmove = 'down'
            elif event.key == K_DOWN:
                tomove = 'down'
                dontmove = 'up'
            elif event.key == K_LEFT:
                tomove = 'left'
                dontmove = 'right'
            elif event.key == K_RIGHT:
                tomove = 'right'
                dontmove = 'left'
            else:
                tomove = snake.movedir
                info(f"  *@[{datetime.datetime.now()}] NOT KEY")
                dontmove = 'left'
                # raise 'RuntimeError, not expected'
            if not currentmovedir == dontmove:
                info(f"  *$[{datetime.datetime.now()}] Turn {tomove}")
                snake.movedir = tomove
    return quit, lose
